package com.szcinda.controller;

import com.szcinda.controller.configuration.UserLoginToken;
import com.szcinda.repository.BusinessCode;
import com.szcinda.service.dto.businessCode.BusinessCodeCreateDto;
import com.szcinda.service.dto.businessCode.BusinessCodeQueryDto;
import com.szcinda.service.dto.businessCode.BusinessService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("bsCode")
public class BusinessCodeController {

    private final BusinessService businessService;

    public BusinessCodeController(BusinessService businessService) {
        this.businessService = businessService;
    }


    @UserLoginToken
    @PostMapping("create")
    @OperationLogAnnotation(operDesc = "创建业务类型")
    public Result<String> create(@RequestBody BusinessCodeCreateDto createDto) {
        businessService.create(createDto);
        return Result.success();
    }

    @GetMapping("del/{id}/{userId}")
    @OperationLogAnnotation(operDesc = "删除业务类型")
    public Result<String> del(@PathVariable String id, @PathVariable String userId) {
        businessService.delete(id, userId);
        return Result.success();
    }

    @UserLoginToken
    @PostMapping("getAll")
    public Result<List<BusinessCode>> query(@RequestBody BusinessCodeQueryDto queryDto) {
        return Result.success(businessService.findAll(queryDto));
    }

    @GetMapping("all")
    public Result<List<BusinessCode>> all() {
        return Result.success(businessService.getAll());
    }
}
